class Offer {
  final int id;
  final String title;
  final String description;
  final num price;
  final num? discount;
  final DateTime? discountEndDate;
  final bool isDeleted;
  final bool isActive;
  final int createdBy;
  final DateTime createdAt;
  final DateTime updatedAt;

  Offer({
    required this.id,
    required this.title,
    required this.description,
    required this.price,
    this.discount,
    this.discountEndDate,
    required this.isDeleted,
    required this.isActive,
    required this.createdBy,
    required this.createdAt,
    required this.updatedAt,
  });

  factory Offer.fromJson(Map<String, dynamic> json) {
    return Offer(
      id: json['offer_id'],
      title: json['offer_title'],
      description: json['offer_description'],
      price: json['offer_price'],
      discount: json['offer_discount'],
      discountEndDate: json['discount_end_date'] != null ? DateTime.parse(json['discount_end_date']) : null,
      isDeleted: json['is_deleted'] == 1,
      isActive: json['active'] == 1,
      createdBy: json['created_by'],
      createdAt: DateTime.parse(json['create_at']),
      updatedAt: DateTime.parse(json['update_at']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'offer_id': id,
      'offer_title': title,
      'offer_description': description,
      'offer_price': price,
      'offer_discount': discount,
      'discount_end_date': discountEndDate?.toIso8601String(),
      'is_deleted': isDeleted ? 1 : 0,
      'active': isActive ? 1 : 0,
      'created_by': createdBy,
      'create_at': createdAt.toIso8601String(),
      'update_at': updatedAt.toIso8601String(),
    };
  }
}
